<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
<div id="app">
    <abc></abc>
    <abc></abc>
    <abc></abc>
</div>

<template id="cpn">
    <div>
        <h3>当前计数：{{counter}}</h3>
        <button @click="add">+</button>
        <button @click="reduce">-</button>
    </div>
</template>
<script src="../js/vue.js"></script>
<script>
    // 若想多个组件共享一个对象，可以声明一个const对象，在data里返回这个对象
    // const obj = {
    //     counter: 0
    // }
    Vue.component('abc', {
        template: '#cpn',
        data() {
            return {
                counter: 0
            }
        },
        // data: {
        //     counter: 0
        // },
        methods: {
            add(){
                this.counter ++;
            },
            reduce(){
                this.counter --;
            }
        },
    })

    const app = new Vue({
        el: '#app'
    })
</script>
</body>
</html>